<?php

class Controller
{

    private $curr_class;
    /*
	 *实例化
	 */
    static final public function getInstance($controll)
    {
        $controll = ucwords($controll);
        static $instances = array();

        if (! isset($instances[$controll]))
        {
            $controll = strtolower($controll);
            $classname = ucfirst($controll.'Controller');
            if (file_exists(CONTROLLER_PATH . $classname . '.php')){
                include_once CONTROLLER_PATH . $classname . '.php';
                $instances[$controll] = new $classname();
                $instances[$controll]->curr_class = $controll;
            }else{
                p('没有找到Controller文件：'.CONTROLLER_PATH . $classname . '.php');
            }
        }
        return $instances[$controll];
    }
    
    final public function input(){
        return Input::getInstance();
    }
    
    final public function session(){
        return Session::getInstance();
    }

    public function __call($fun,$arg){
        echo '{"statusCode":"300","message":"对不起，您访问的控制器不存在！<br/>'.$this->curr_class.'::'.$fun.'"}';
        exit;
    }

    public function model($model = null){
        $model = $model === null ? $this->curr_class : $model;

        return Model::getInstance($model);
    }
}

?>